using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.System;


namespace HengTong.ViewModel._Admin.SysTodoCenterVms
{
    public partial class SysTodoCenterListVm : BasePagedListVM<SysTodoCenterView, SysTodoCenterSearcher>
    {

        protected override IEnumerable<IGridColumn<SysTodoCenterView>> InitGridHeader()
        {
            return new List<GridColumn<SysTodoCenterView>>{
                this.MakeGridHeader(x => x.Title),
                this.MakeGridHeader(x => x.BillCode),
                this.MakeGridHeader(x => x.BusinessType),
                this.MakeGridHeader(x => x.ActivityId),
                this.MakeGridHeader(x => x.WorkflowId),
                this.MakeGridHeader(x => x.Company),
                this.MakeGridHeader(x => x.Department),
                this.MakeGridHeader(x => x.Submitter),
                this.MakeGridHeader(x => x.Approver),
                this.MakeGridHeader(x => x.CreateBy),
                this.MakeGridHeader(x => x.ApproveResult),
                this.MakeGridHeader(x => x.Status),
                this.MakeGridHeader(x => x.Priority),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeader(x => x.DueDate),
                this.MakeGridHeader(x => x.CompleteTime),
                this.MakeGridHeader(x => x.PcRoute),
                this.MakeGridHeader(x => x.MobileRoute),
                this.MakeGridHeader(x => x.BusinessId),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysTodoCenterView> GetSearchQuery()
        {
            var query = DC.Set<SysTodoCenter>()
                .CheckContain(Searcher.BillCode, x=>x.BillCode)
                .CheckContain(Searcher.BusinessType, x=>x.BusinessType)
                .CheckContain(Searcher.Company, x=>x.Company)
                .CheckContain(Searcher.Department, x=>x.Department)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckEqual(Searcher.Priority, x=>x.Priority)
                .CheckEqual(Wtm.LoginUserInfo.ITCode, x => x.CreateBy)
                .CheckContain(Searcher.Submitter, x=>x.Submitter)
                .Select(x => new SysTodoCenterView
                {
				    ID = x.ID,
                    Title = x.Title,
                    BillCode = x.BillCode,
                    Route = x.Route,
                    BusinessType = x.BusinessType,
                    ActivityId = x.ActivityId,
                    WorkflowId = x.WorkflowId,
                    Company = x.Company,
                    Department = x.Department,
                    Submitter = x.Submitter,
                    Approver = x.Approver,
                    CreateBy = x.CreateBy,
                    ApproveResult = x.ApproveResult,
                    Status = x.Status,
                    Priority = x.Priority,
                    CreateTime = x.CreateTime,
                    DueDate = x.DueDate,
                    CompleteTime = x.CompleteTime,
                    PcRoute = x.Route.PcRoute,
                    MobileRoute = x.Route.MobileRoute,
                    BusinessId = x.BusinessId
                })
                .OrderByDescending(x => x.CreateTime);
            return query;
        }

    }

    public class SysTodoCenterView : SysTodoCenter{
        [Display(Name = "路由地址", Description = "单据的访问路由地址", GroupName = "基本信息")]
        [StringLength(128)]
        public string PcRoute { get; set; }
    
        [Display(Name = "移动端路由地址", Description = "单据的访问路由地址", GroupName = "基本信息")]
        [StringLength(128)]
        public string MobileRoute { get; set; }
    }
}
